package com.tamtamy.jtta.data.json;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.tamtamy.jtta.data.CommentList;
import com.tamtamy.jtta.exception.NoResultException;
import com.tamtamy.jtta.exception.ParsingException;

public class JSONCommentList extends CommentList {
	
	private static final long serialVersionUID = 7475168875919788915L;

	public JSONCommentList(JSONObject jsonObject) throws NoResultException, ParsingException {
		super();
		JSONArray commentListJSON = (JSONArray)jsonObject.get("list");
		if (commentListJSON == null || commentListJSON.size()==0){
			throw new NoResultException("No comments found");
		}
		for (int i = 0; i < commentListJSON.size(); i++) {
			JSONObject commentJSON = commentListJSON.getJSONObject(i);
			this.add(new JSONComment(commentJSON));
		}		
	}

}
